home *** CD-ROM | disk | FTP | other *** search
- /*=========================================================================
- Module: SortSelection
-
- Purpose: Get a selection and sort it. Then update the selection with
- the sorted selection.
-
- returns: UpdateSel to the scrap.
-
- Functional Details:
-
- Get a valid selection
- if error
- exit
- Build the selection into lines of text
- if error
- exit
- Sort the selection lines
- Update the selection with the sorted lines
- if error
- exit
- Dispose all allocated storage
-
- =========================================================================*/
- #include "ToolSort.h"
- #include <SetUpA4.h>
-
- void
- main()
- {
- SelLine selLine; /* Array of handles to selection lines */
- SelRec validSel; /* Handle to selection and selection length */
- Text txt; /* Handle to selection in text format */
- long err;
- long size;
- int i;
- long oldA4;
- EvQElPtr qel;
-
- oldA4=SetUpA4(); /* Globals accessed off of A4 */
-
- GetValidSel( &validSel);
-
- if ( validSel.sel != NIL )
- {
- err = BuildLines(validSel, &selLine);
- DisposHandle( validSel.sel ); /* free memory */
-
- if (selLine.noLines > 0) /* test 1 line */
- {
-
- Bubble(selLine.lines, sizeof(selLine.lines[0]),
- selLine.noLines, Comp, Swap);
-
- err = SelToText( selLine, &txt );
-
- for ( i=0; i<selLine.noLines; i++ ) /* Dispose selLine */
- {
- if ( selLine.lines[i] != NIL )
- {
- DisposHandle( selLine.lines[i] );
- selLine.lines[i] = 0L; /* mark it disposed */
- }
- }
- if ( selLine.lines != NIL )
- {
- DisposPtr((Ptr)( selLine.lines ));
- selLine.lines = 0L; /* mark it disposed */
- }
-
- if ( txt != NIL )
- {
- err = UpdateSel( txt );
- DisposHandle( txt );
-
- }
- }
- }
-
-
- if (PPostEvent(3, 2422, &qel)==noErr)
- {
- qel->evtQModifiers = cmdKey;
- }
-
- RestoreA4(oldA4); /* restore reg A4 to its original value */
- }